import { ElementEntity } from './ElementEntity';
import { COLOR, formarColor, CreatePosition } from '../Config'

class PolylineEntity extends ElementEntity {
    constructor(options = {}) {
        super(options.id, options, options.onClick, options.onRightClick);
        this.EntityTypeName = 'ElementEntity'
        this.color = formarColor(options.color) || COLOR.MarkViewColor;
        this.lineType = options.lineType || 'solid';
        this.width = options.width || 3;
        if (this.lineType == 'solid') {
            this.material = this.color;
        } else if (this.lineType == 'dash') {
            this.material = new Cesium.PolylineDashMaterialProperty({
                color: this.color,
                gapColor: Cesium.Color.TRANSPARENT,
                dashLength: options.dashLength || 16,
            });
        } else if (this.lineType == 'arrow') {
            this.material = new Cesium.PolylineArrowMaterialProperty(this.color);
        }
        this.Points = [];
        for (let i = 0; i < options.points.length; i++) {
            const element = options.points[i];
            this.Points.push(CreatePosition(element));
        };
        this.Entity.polyline = {
            positions: this.Points,
            material: this.material,  // 线的颜色
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            width: this.width, // 宽度
            clampToGround: true,
        }
    }
};


export default PolylineEntity